package com.brother.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.brother.database.DataBase;
import com.brother.model.AlarmTypeText;

public class AlarmTypeService {

private static final List<AlarmTypeText> alarms = new ArrayList<AlarmTypeText>();
private static Logger log = Logger.getLogger(AlarmTypeService.class);
public static String getAlarmType(String state, String language){
	if(alarms.size() == 0){
		String sql = "select * from alarmType";
		try {
			ResultSet rs = DataBase.query(sql);
			while(rs.next()){
				AlarmTypeText at = new AlarmTypeText();
				at.setAlarmTypeId(rs.getInt("alarmTypeId"));
				at.setLanguage(rs.getString("language"));
				at.setState(rs.getString("state"));
				at.setTypeName(rs.getString("typeName"));
				alarms.add(at);
			}
		} catch (SQLException e) {
			log.error("", e);
		}finally{
			DataBase.closeThreadConnection();
		}
	}
	for(int i=0; i < alarms.size();i++){
		if(alarms.get(i).getState().equals(state) && (language == null 
				|| alarms.get(i).getLanguage().equals(language))){
			String n = alarms.get(i).getTypeName();
			return n == null?"":n;
		}
	}
	return "";
}
	
}
